package com.yunkeji.api.pay.controller;

import com.yunkeji.api.pay.bo.PayBo;
import com.yunkeji.api.pay.bo.RechargeBo;
import com.yunkeji.api.pay.bo.WithDrawBo;
import com.yunkeji.api.pay.bo.WithDrawListBo;
import com.yunkeji.api.pay.service.PayService;
import com.yunkeji.api.pay.vo.PrePayVo;
import com.yunkeji.api.pay.vo.RechargeList;
import com.yunkeji.api.pay.vo.RechargePlanVo;
import com.yunkeji.api.pay.vo.VipPlanVo;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.dao.domain.PayLog;
import com.yunkeji.dao.domain.PayWithdrawPlan;
import com.yunkeji.dao.vo.PayLogVo;
import com.yunkeji.dao.vo.PayWithdrawVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.concurrent.TimeUnit;

/** 支付 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/pay")
public class PayController extends BaseController {
    private final PayService payService;

    /** 获取充值计划 */
    @PostMapping("/rechargePlan")
    public R<List<RechargePlanVo>> rechargePlan() {
        return R.ok(payService.rechargePlan());
    }

    /** 获取提现计划 */
    @PostMapping("/withdrawPlan")
    public R<List<PayWithdrawPlan>> withdrawPlan() {
        return R.ok(payService.withdrawPlan());
    }

    /** 获取会员计划 */
    @PostMapping("/vipPlan")
    public R<List<VipPlanVo>> vipPlan() {
        return R.ok(payService.vipPlan());
    }

    /** 充值金币 */
    @PostMapping("/rechargeGoldPre")
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快,五秒后再试")
    public R<PrePayVo> rechargeGoldPre(@RequestBody @Valid PayBo bo) {
        return R.ok(payService.rechargeGoldPre(bo));
    }

    /** 成为会员 */
    @PostMapping(value = "/becomeMember")
    @ResponseBody
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快,五秒后再试")
    public R<PrePayVo> appPay(@RequestBody @Valid PayBo bo) {
        PrePayVo vo = payService.becomeMember(bo);
        return R.ok(vo);
    }

    /** 发起提现 */
    @PostMapping("/withdraw")
    @RepeatSubmit(interval = 1, timeUnit = TimeUnit.MINUTES, message = "发起提现请求频繁,请稍后再试")
    public R withdraw(@Valid @RequestBody WithDrawBo bo) {
        payService.withdraw(bo);
        return R.ok();
    }

    /** 发起提现记录 */
    @PostMapping("/withdrawList")
    public TableDataInfo<PayWithdrawVo> withdrawList(@RequestBody WithDrawListBo bo) {
        return payService.withdrawList(bo);
    }

    /** 充值记录 */
    @PostMapping("/rechargeList")
    public TableDataInfo<RechargeList> rechargeList(@RequestBody RechargeBo bo) {
        return payService.rechargeList(bo);
    }

    /** 收益明细 */
    @PostMapping("/earnDetail")
    public TableDataInfo<PayLog> earnDetail(@RequestBody RechargeBo bo) {
        return payService.earnDetail(bo);
    }

    /** 支出明细 */
    @PostMapping("/payDetail")
    public TableDataInfo<PayLogVo> payDetail(@RequestBody RechargeBo bo) {
        return payService.payDetail(bo);
    }
}
